home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / orig-emacs-src / emacs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-23  |  18.7 KB  |  785 lines  |  [TEXT/EMAC]

  1. /* Fully extensible Emacs, running on Unix, intended for GNU.
  2.    Copyright (C) 1985, 1986, 1987, 1990 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This must precede sys/signal.h on certain machines.  */
  22. #include "sys/types.h" /* CHANGED FOR MAC */
  23. #include "signal.h" /* CHANGED FOR MAC */
  24. #include "errno.h" /* CHANGED FOR MAC */
  25.  
  26. #include "config.h"
  27. #ifdef NULL
  28. #undef NULL
  29. #endif
  30. #include "lisp.h"
  31. #undef NULL
  32. #include "commands.h"
  33.  
  34. /* Get FIONREAD, if it is available,
  35.    just to help decide whether SIGIO should be defined.  */
  36. #ifdef USG
  37. #include <termio.h>
  38. #include <fcntl.h>
  39. #else /* not USG */
  40. #ifndef VMS
  41. #include "sys/ioctl.h" /* CHANGED FOR MAC */
  42. #endif /* not VMS */
  43. #endif /* not USG */
  44.  
  45. /* Allow m- file to inhibit use of FIONREAD.  */
  46. #ifdef BROKEN_FIONREAD
  47. #undef FIONREAD
  48. #endif
  49.  
  50. /* We are unable to use interrupts if FIONREAD is not available,
  51.    so flush SIGIO so we won't try. */
  52. #ifndef FIONREAD
  53. #ifdef SIGIO
  54. #undef SIGIO
  55. #endif
  56. #endif
  57.  
  58. #include "stdio.h" /* CHANGED FOR MAC */
  59. #include "sys/file.h" /* CHANGED FOR MAC */
  60.  
  61. #ifdef VMS
  62. #include <ssdef.h>
  63. #endif
  64.  
  65. #if 0 /* fcntl.h was included above.  */
  66. #ifdef USG5
  67. #include <fcntl.h>
  68. #endif
  69. #endif
  70.  
  71. #ifdef BSD
  72. #include "sys/ioctl.h" /* CHANGED FOR MAC */
  73. #endif
  74.  
  75. #ifdef APOLLO
  76. #ifndef APOLLO_SR10
  77. #include <default_acl.h>
  78. #endif
  79. #endif
  80.  
  81. #ifndef O_RDWR
  82. #define O_RDWR 2
  83. #endif
  84.  
  85. #define PRIO_PROCESS 0
  86.  
  87. /* Command line args from shell, as list of strings */
  88. Lisp_Object Vcommand_line_args;
  89.  
  90. /* Hook run by `kill-emacs' before it does really anything.  */
  91. Lisp_Object Vkill_emacs_hook;
  92.  
  93. /* Set nonzero after Emacs has started up the first time.
  94.   Prevents reinitialization of the Lisp world and keymaps
  95.   on subsequent starts.  */
  96. int initialized;
  97.  
  98. /* Variable whose value is symbol giving operating system type */
  99. Lisp_Object Vsystem_type;
  100.   
  101. /* If non-zero, emacs should not attempt to use an window-specific code,
  102.    but instead should use the virtual terminal under which it was started */
  103. int inhibit_window_system;
  104.  
  105. #ifdef HAVE_X_WINDOWS
  106. /* If -d option is used, this variable points to the name of
  107.    the display to use.  */
  108. char *alternate_display;
  109. char **xargv;
  110. int xargc;
  111. #endif /* HAVE_X_WINDOWS */
  112.  
  113. #ifdef USG_SHARED_LIBRARIES
  114. /* If nonzero, this is the place to put the end of the writable segment
  115.    at startup.  */
  116.  
  117. unsigned int bss_end = 0;
  118. #endif
  119.  
  120. /* Nonzero means running Emacs without interactive terminal.  */
  121.  
  122. int noninteractive;
  123.  
  124. /* Value of Lisp variable `noninteractive'.
  125.    Normally same as C variable `noninteractive'
  126.    but nothing terrible happens if user sets this one.  */
  127.  
  128. int noninteractive1;
  129.  
  130. /* Signal code for the fatal signal that was received */
  131. int fatal_error_code;
  132.  
  133. /* Nonzero if handling a fatal error already */
  134. int fatal_error_in_progress;
  135.  
  136. /* Handle bus errors, illegal instruction, etc. */
  137. fatal_error_signal (sig)
  138.      int sig;
  139. {
  140. #ifdef BSD
  141.   int tpgrp;
  142. #endif /* BSD */
  143.  
  144.   fatal_error_code = sig;
  145.   signal (sig, SIG_DFL);
  146.  
  147.   /* If fatal error occurs in code below, avoid infinite recursion.  */
  148.   if (fatal_error_in_progress)
  149.     kill (getpid (), fatal_error_code);
  150.  
  151.   fatal_error_in_progress = 1;
  152.  
  153.   /* If we are controlling the terminal, reset terminal modes */
  154. #ifdef BSD
  155.   if (ioctl(0, TIOCGPGRP, &tpgrp) == 0
  156.       && tpgrp == getpgrp (0))
  157. #endif /* BSD */
  158.     {
  159.       reset_sys_modes ();
  160.       if (sig != SIGTERM)
  161.     fprintf (stderr, "Fatal error (%d).", sig);
  162.     }
  163.  
  164.   /* Clean up */
  165. #ifdef subprocesses
  166.   kill_buffer_processes (Qnil);
  167. #endif
  168.   Fdo_auto_save (Qt);
  169.  
  170. #ifdef CLASH_DETECTION
  171.   unlock_all_files ();
  172. #endif /* CLASH_DETECTION */
  173.  
  174. #ifdef VMS
  175.   kill_vms_processes ();
  176.   LIB$STOP (SS$_ABORT);
  177. #else
  178.   /* Signal the same code; this time it will really be fatal.  */
  179.   kill (getpid (), fatal_error_code);
  180. #endif /* not VMS */
  181. }
  182.  
  183. /* Code for dealing with Lisp access to the Unix command line */
  184.  
  185. static
  186. init_cmdargs (argc, argv, skip_args)
  187.      int argc;
  188.      char **argv;
  189.      int skip_args;
  190. {
  191.   register int i;
  192.  
  193.   Vcommand_line_args = Qnil;
  194.  
  195.   for (i = argc - 1; i >= 0; i--)
  196.     {
  197.       if (i == 0 || i > skip_args)
  198.     Vcommand_line_args
  199.       = Fcons (build_string (argv[i]), Vcommand_line_args);
  200.     }
  201. }
  202.  
  203. #ifdef VMS
  204. #ifdef LINK_CRTL_SHARE
  205. #ifdef SHAREABLE_LIB_BUG
  206. #ifdef __GNUC__
  207. #define    environ $$PsectAttributes_NOSHR$$environ
  208. extern char **environ;
  209. #else
  210. extern noshare char **environ;
  211. #endif
  212. #endif /* SHAREABLE_LIB_BUG */
  213. #endif /* LINK_CRTL_SHARE */
  214. #endif /* VMS */
  215.  
  216. /* We don't include crtbegin.o and crtend.o in the link,
  217.    so these functions and variables might be missed.
  218.    Provide dummy definitions to avoid error.
  219.    (We don't have any real constructors or destructors.)  */
  220. #ifdef __GNUC__
  221. #ifndef ORDINARY_LINK
  222. __do_clobal_ctors ()
  223. {}
  224. __do_clobal_ctors_aux ()
  225. {}
  226. __do_global_dtors ()
  227. {}
  228. char * __CTOR_LIST__[2] = { (char *) (-1), 0 };
  229. char * __DTOR_LIST__[2] = { (char *) (-1), 0 };
  230. __main ()
  231. {}
  232. #endif /* not ORDINARY_LINK */
  233. #endif /* __GNUC__ */
  234.  
  235. /* ARGSUSED */
  236. main1 (argc, argv, envp) /* CHANGED FOR MAC, main renamed to main1 */
  237.      int argc;
  238.      char **argv;
  239.      char **envp;
  240. {
  241.   int skip_args = 0;
  242.   extern int errno;
  243.   extern void malloc_warning ();
  244.  
  245. /* Map in shared memory, if we are using that.  */
  246. #ifdef HAVE_SHM
  247.   if (argc > 1 && !strcmp (argv[1], "-nl"))
  248.     {
  249.       map_in_data (0);
  250.       /* The shared memory was just restored, which clobbered this.  */
  251.       skip_args = 1;
  252.     }
  253.   else
  254.     {
  255.       map_in_data (1);
  256.       /* The shared memory was just restored, which clobbered this.  */
  257.       skip_args = 0;
  258.     }
  259. #endif
  260.  
  261. #ifdef VMS
  262.   /* If -map specified, map the data file in */
  263.   if (argc > 2 && ! strcmp (argv[1], "-map"))
  264.     {
  265.       skip_args = 2;
  266.       mapin_data (argv[2]);
  267.     }
  268.  
  269. #ifdef LINK_CRTL_SHARE
  270. #ifdef SHAREABLE_LIB_BUG
  271.   /* Bletcherous shared libraries! */
  272.   if (!stdin)
  273.     stdin = fdopen (0, "r");
  274.   if (!stdout)
  275.     stdout = fdopen (1, "w");
  276.   if (!stderr)
  277.     stderr = fdopen (2, "w");
  278.   if (!environ)
  279.     environ = envp;
  280. #endif /* SHAREABLE_LIB_BUG */
  281. #endif /* LINK_CRTL_SHARE */
  282. #endif /* VMS */
  283.  
  284. #ifdef USG_SHARED_LIBRARIES
  285.   if (bss_end)
  286.     brk (bss_end);
  287. #endif
  288.  
  289. #ifdef NeXT
  290.   extern int malloc_cookie;
  291.  
  292.   /* This helps out unexnext.c.  */
  293.   if (initialized)
  294.     if (malloc_jumpstart (malloc_cookie) != 0)
  295.       printf ("malloc jumpstart failed!\012");
  296. #endif /* NeXT */
  297.  
  298.   clearerr (stdin);
  299.  
  300. #ifdef APOLLO
  301. #ifndef APOLLO_SR10
  302.   /* If USE_DOMAIN_ACLS environment variable exists,
  303.      use ACLs rather than UNIX modes. */
  304.   if (egetenv ("USE_DOMAIN_ACLS"))
  305.     default_acl (USE_DEFACL);
  306. #endif
  307. #endif /* APOLLO */
  308.  
  309. #ifndef SYSTEM_MALLOC
  310.   /* Arrange for warnings when nearly out of space.  */
  311.   malloc_init (0, malloc_warning);
  312. #endif
  313.  
  314. #ifdef HIGHPRI
  315.   setpriority (PRIO_PROCESS, getpid (), HIGHPRI);
  316.   setuid (getuid ());
  317. #endif HIGHPRI
  318.  
  319.   inhibit_window_system = 0;
  320.  
  321. #ifdef HAVE_X_WINDOWS
  322.   xargv = argv;
  323.   xargc = argc;
  324. #endif
  325.  
  326. /* Handle the -t switch, which specifies filename to use as terminal */
  327.   if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t"))
  328.     {
  329.       skip_args += 2;
  330.       close (0);
  331.       close (1);
  332.       open (argv[skip_args], O_RDWR, 2 );
  333.       dup (0);
  334.       fprintf (stderr, "Using %s\012", argv[skip_args]);
  335. #ifdef HAVE_X_WINDOWS
  336.       inhibit_window_system = 1;    /* -t => -nw */
  337. #endif
  338.     }
  339. #ifdef HAVE_X_WINDOWS
  340. /* Handle the -d switch, which means use a different display for X */
  341.   if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-d") ||
  342.                    !strcmp (argv[skip_args + 1], "-display")))
  343.     {
  344.       skip_args += 2;
  345.       alternate_display = argv[skip_args];
  346.     } 
  347.   else
  348.     alternate_display = 0;
  349. #endif    /* HAVE_X_WINDOWS */
  350.  
  351.   if (skip_args + 1 < argc
  352.       && (!strcmp (argv[skip_args + 1], "-nw")))
  353.     {
  354.       skip_args += 1;
  355.       inhibit_window_system = 1;
  356.     }
  357.  
  358. /* Handle the -batch switch, which means don't do interactive display.  */
  359.   noninteractive = 0;
  360.   if (skip_args + 1 < argc && !strcmp (argv[skip_args + 1], "-batch"))
  361.     {
  362.       skip_args += 1;
  363.       noninteractive = 1;
  364.     }
  365.  
  366. #ifdef POSIX_SIGNALS
  367.   init_signals ();
  368. #endif
  369.  
  370. #ifdef HAVE_TZSET
  371.   /* Reinitialize the time zone if it was initialized before dumping Emacs.  */
  372.   if (initialized)
  373.     tzset ();
  374. #endif
  375.  
  376.   if (
  377. #ifndef CANNOT_DUMP
  378.       ! noninteractive || initialized
  379. #else
  380.       1
  381. #endif
  382.       )
  383.     {
  384.       /* Don't catch these signals in batch mode if not initialized.
  385.      On some machines, this sets static data that would make
  386.      signal fail to work right when the dumped Emacs is run.  */
  387.       signal (SIGHUP, fatal_error_signal);
  388.       signal (SIGQUIT, fatal_error_signal);
  389.       signal (SIGILL, fatal_error_signal);
  390.       signal (SIGTRAP, fatal_error_signal);
  391.       signal (SIGIOT, fatal_error_signal);
  392. #ifdef SIGEMT
  393.       signal (SIGEMT, fatal_error_signal);
  394. #endif
  395.       signal (SIGFPE, fatal_error_signal);
  396.       signal (SIGBUS, fatal_error_signal);
  397.       signal (SIGSEGV, fatal_error_signal);
  398.       signal (SIGSYS, fatal_error_signal);
  399.       signal (SIGTERM, fatal_error_signal);
  400. #ifdef SIGXCPU
  401.       signal (SIGXCPU, fatal_error_signal);
  402. #endif
  403. #ifdef SIGXFSZ
  404.       signal (SIGXFSZ, fatal_error_signal);
  405. #endif SIGXFSZ
  406.  
  407. #ifdef AIX
  408.       /* This used to run fatal_error_signal,
  409.      but it isn't fatal.  There's nothing Emacs can usefully do.
  410.      Might as well let the system kill us if it insists.  */
  411.       signal (SIGDANGER, SIG_IGN);
  412.       signal (20, fatal_error_signal);
  413.       signal (21, fatal_error_signal);
  414.       signal (22, fatal_error_signal);
  415.       signal (23, fatal_error_signal);
  416.       signal (24, fatal_error_signal);
  417. #ifdef SIGIO
  418.       signal (SIGAIO, fatal_error_signal);
  419.       signal (SIGPTY, fatal_error_signal);
  420. #endif
  421. #ifdef SIGURG
  422.       /* Note that SIGIOINT is the same as SIGIO on some machines,
  423.      and the same as SIGURG on others.  It seems ore reliable to use the
  424.      name with a uniform meaning.  */
  425.       signal (SIGURG, fatal_error_signal);
  426. #endif
  427.       signal (SIGGRANT, fatal_error_signal);
  428.       signal (SIGRETRACT, fatal_error_signal);
  429.       signal (SIGSOUND, fatal_error_signal);
  430.       signal (SIGMSG, fatal_error_signal);
  431. #endif /* AIX */
  432.     }
  433.  
  434.   noninteractive1 = noninteractive;
  435.  
  436. /* Perform basic initializations (not merely interning symbols) */
  437.  
  438.   if (!initialized)
  439.     {
  440.       init_alloc_once ();
  441.       init_obarray ();
  442.       init_eval_once ();
  443.       init_syntax_once ();    /* Create standard syntax table.  */
  444.               /* Must be done before init_buffer */
  445.       init_buffer_once ();    /* Create buffer table and some buffers */
  446.       init_minibuf_once ();    /* Create list of minibuffers */
  447.                   /* Must precede init_window_once */
  448.       init_window_once ();    /* Init the window system */
  449.     }
  450.  
  451.   init_alloc ();
  452. #ifdef MAINTAIN_ENVIRONMENT
  453.   init_environ ();
  454. #endif
  455.   init_eval ();
  456.   init_data ();
  457.   init_read ();
  458.  
  459.   init_cmdargs (argc, argv, skip_args);    /* Create list Vcommand_line_args */
  460.   init_buffer ();    /* Init default directory of main buffer */
  461.   if (!noninteractive)
  462.     {
  463. #ifdef VMS
  464.       init_vms_input ();/* init_display calls get_screen_size, that needs this */
  465. #endif /* VMS */
  466.       init_display ();    /* Determine terminal type.  init_sys_modes uses results */
  467.     }
  468.   init_keyboard ();    /* This too must precede init_sys_modes */
  469.   init_callproc ();    /* And this too. */
  470.   init_sys_modes ();    /* Init system terminal modes (RAW or CBREAK, etc.) */
  471.   init_xdisp ();
  472.   init_macros ();
  473.   init_editfns ();
  474. #ifdef VMS
  475.   init_vmsfns ();
  476. #endif /* VMS */
  477. #ifdef subprocesses
  478.   init_process ();
  479. #endif /* subprocesses */
  480.   init_apple(); /* CHANGED FOR MAC */
  481.  
  482. /* Intern the names of all standard functions and variables; define standard keys */
  483.  
  484.   if (!initialized)
  485.     {
  486.       /* The basic levels of Lisp must come first */
  487.       /* And data must come first of all
  488.      for the sake of symbols like error-message */
  489.       syms_of_data ();
  490.       syms_of_alloc ();
  491. #ifdef MAINTAIN_ENVIRONMENT
  492.       syms_of_environ ();
  493. #endif MAINTAIN_ENVIRONMENT
  494.       syms_of_read ();
  495.       syms_of_print ();
  496.       syms_of_eval ();
  497.       syms_of_fns ();
  498.  
  499.       syms_of_abbrev ();
  500.       syms_of_buffer ();
  501.       syms_of_bytecode ();
  502.       syms_of_callint ();
  503.       syms_of_casefiddle ();
  504.       syms_of_callproc ();
  505.       syms_of_cmds ();
  506. #ifndef NO_DIR_LIBRARY
  507.       syms_of_dired ();
  508. #endif /* not NO_DIR_LIBRARY */
  509.       syms_of_display ();
  510.       syms_of_doc ();
  511.       syms_of_editfns ();
  512.       syms_of_emacs ();
  513.       syms_of_fileio ();
  514. #ifdef CLASH_DETECTION
  515.       syms_of_filelock ();
  516. #endif /* CLASH_DETECTION */
  517.       syms_of_indent ();
  518.       syms_of_keyboard ();
  519.       syms_of_keymap ();
  520.       syms_of_macros ();
  521.       syms_of_marker ();
  522.       syms_of_minibuf ();
  523.       syms_of_mocklisp ();
  524. #ifdef subprocesses
  525.       syms_of_process ();
  526. #endif /* subprocesses */
  527.       syms_of_search ();
  528.       syms_of_syntax ();
  529.       syms_of_undo ();
  530.       syms_of_window ();
  531.       syms_of_xdisp ();
  532. #ifdef HAVE_X_WINDOWS
  533.       syms_of_xfns ();
  534. #ifdef HAVE_X_MENU
  535.       syms_of_xmenu ();
  536. #endif /* HAVE_X_MENU */
  537. #endif /* HAVE_X_WINDOWS */
  538.  
  539. #ifdef SYMS_SYSTEM
  540.       SYMS_SYSTEM;
  541. #endif
  542.  
  543. #ifdef SYMS_MACHINE
  544.       SYMS_MACHINE;
  545. #endif
  546.  
  547.       keys_of_casefiddle ();
  548.       keys_of_cmds ();
  549.       keys_of_buffer ();
  550.       keys_of_keyboard ();
  551.       keys_of_keymap ();
  552.       keys_of_macros ();
  553.       keys_of_minibuf ();
  554.       keys_of_window ();
  555.     }
  556.  
  557.   if (!initialized)
  558.     {
  559.       /* Handle -l loadup-and-dump, args passed by Makefile. */
  560.       if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l"))
  561.     Vtop_level = Fcons (intern ("load"),
  562.                 Fcons (build_string (argv[2 + skip_args]), Qnil));
  563.  
  564. #undef CANNOT_DUMP /* CHANGED FOR MAC */
  565. #define HAVE_SHM /* CHANGED FOR MAC */
  566.  
  567. #ifdef CANNOT_DUMP
  568.       /* Unless next switch is -nl, load "loadup.el" first thing.  */
  569.       if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl")))
  570.     Vtop_level = Fcons (intern ("load"),
  571.                 Fcons (build_string ("loadup.el"), Qnil));
  572. #endif /* CANNOT_DUMP */
  573.     }
  574.  
  575.   initialized = 1;
  576.  
  577.   /* Enter editor command loop.  This never returns.  */
  578.   Frecursive_edit ();
  579.   /* NOTREACHED */
  580. }
  581.  
  582. DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
  583.   "Exit the Emacs job and kill it.  ARG means no query.\012\
  584. If emacs is running noninteractively and ARG is an integer,\012\
  585. return ARG as the exit program code.")
  586.   (arg)
  587.      Lisp_Object arg;
  588. {
  589.   Lisp_Object answer;
  590.   int i;
  591.   struct gcpro gcpro1;
  592.  
  593.   GCPRO1 (arg);
  594.  
  595.   if (!EQ (Vkill_emacs_hook, Qnil))
  596.     call0 (Vkill_emacs_hook);
  597.  
  598.   if (feof (stdin))
  599.     arg = Qt;
  600.  
  601. #ifdef subprocesses
  602.   kill_buffer_processes (Qnil);
  603. #endif /* subprocesses */
  604.  
  605. #ifdef VMS
  606.   kill_vms_processes ();
  607. #endif /* VMS */
  608.  
  609.   Fdo_auto_save (Qt);
  610.  
  611. #ifdef CLASH_DETECTION
  612.   unlock_all_files ();
  613. #endif /* CLASH_DETECTION */
  614.  
  615.   fflush (stdout);
  616.   reset_sys_modes ();
  617.   UNGCPRO;
  618.  
  619. /* Is it really necessary to do this deassign
  620.    when we are going to exit anyway?  */
  621. /* #ifdef VMS
  622.   stop_vms_input ();
  623.  #endif  */
  624.   stuff_buffered_input (arg);
  625. #ifdef SIGIO
  626.   /* There is a tendency for a SIGIO signal to arrive within exit,
  627.      and cause a SIGHUP because the input descriptor is already closed.  */
  628.   unrequest_sigio ();
  629.   signal (SIGIO, SIG_IGN);
  630. #endif
  631.   exit ((XTYPE (arg) == Lisp_Int) ? XINT (arg)
  632. #ifdef VMS
  633.     : 1
  634. #else
  635.     : 0
  636. #endif
  637.     );
  638.   /* NOTREACHED */
  639. }
  640.  
  641. #ifndef CANNOT_DUMP
  642. /* Nothing like this can be implemented on an Apollo.
  643.    What a loss!  */
  644.  
  645. #ifdef HAVE_SHM
  646.  
  647. DEFUN ("dump-emacs-data", Fdump_emacs_data, Sdump_emacs_data, 1, 1, 0,
  648.   "Dump current state of Emacs into data file FILENAME.\012\
  649. This function exists on systems that use HAVE_SHM.")
  650.   (intoname)
  651.      Lisp_Object intoname;
  652. {
  653.   extern int my_edata;
  654.   Lisp_Object tem;
  655.   extern void malloc_warning ();
  656.  
  657.   CHECK_STRING (intoname, 0);
  658.   intoname = Fexpand_file_name (intoname, Qnil);
  659.  
  660.   tem = Vpurify_flag;
  661.   Vpurify_flag = Qnil;
  662.  
  663.   fflush (stdout);
  664.   /* Tell malloc where start of impure now is */
  665.   /* Also arrange for warnings when nearly out of space.  */
  666. #ifndef SYSTEM_MALLOC
  667.   malloc_init (&my_edata, malloc_warning);
  668. #endif
  669.   map_out_data (XSTRING (intoname)->data);
  670.  
  671.   Vpurify_flag = tem;
  672.  
  673.   return Qnil;
  674. }
  675.  
  676. #else /* not HAVE_SHM */
  677.  
  678. DEFUN ("dump-emacs", Fdump_emacs, Sdump_emacs, 2, 2, 0,
  679.   "Dump current state of Emacs into executable file FILENAME.\012\
  680. Take symbols from SYMFILE (presumably the file you executed to run Emacs).")
  681.   (intoname, symname)
  682.      Lisp_Object intoname, symname;
  683. {
  684.   extern int my_edata;
  685.   Lisp_Object tem;
  686.   extern void malloc_warning ();
  687.  
  688.   CHECK_STRING (intoname, 0);
  689.   intoname = Fexpand_file_name (intoname, Qnil);
  690.   if (!EQ (symname, Qnil))
  691.     {
  692.       CHECK_STRING (symname, 0);
  693.       if (XSTRING (symname)->size)
  694.     symname = Fexpand_file_name (symname, Qnil);
  695.     }
  696.  
  697.   tem = Vpurify_flag;
  698.   Vpurify_flag = Qnil;
  699.  
  700.   fflush (stdout);
  701. #ifdef VMS
  702.   mapout_data (XSTRING (intoname)->data);
  703. #else
  704.   /* Tell malloc where start of impure now is */
  705.   /* Also arrange for warnings when nearly out of space.  */
  706. #ifndef SYSTEM_MALLOC
  707.   malloc_init (&my_edata, malloc_warning);
  708. #endif
  709.   unexec (XSTRING (intoname)->data,
  710.       !EQ (symname, Qnil) ? XSTRING (symname)->data : 0, &my_edata, 0, 0);
  711. #endif /* not VMS */
  712.  
  713.   Vpurify_flag = tem;
  714.  
  715.   return Qnil;
  716. }
  717.  
  718. #endif /* not HAVE_SHM */
  719.  
  720. #endif /* not CANNOT_DUMP */
  721.  
  722. #ifdef VMS
  723. #define SEPCHAR ','
  724. #else
  725. #define SEPCHAR ':'
  726. #endif
  727.  
  728. Lisp_Object
  729. decode_env_path (evarname, defalt)
  730.      char *evarname, *defalt;
  731. {
  732.   register char *path, *p;
  733.   extern char *index ();
  734.  
  735.   Lisp_Object lpath;
  736.  
  737.   if (evarname != 0)
  738.     path = (char *) egetenv (evarname);
  739.   else
  740.     path = 0;
  741.   if (!path)
  742.     path = defalt;
  743.   lpath = Qnil;
  744.   while (1)
  745.     {
  746.       p = index (path, SEPCHAR);
  747.       if (!p) p = path + strlen (path);
  748.       lpath = Fcons (p - path ? make_string (path, p - path) : Qnil,
  749.              lpath);
  750.       if (*p)
  751.     path = p + 1;
  752.       else
  753.     break;
  754.     }
  755.   return Fnreverse (lpath);
  756. }
  757.  
  758. syms_of_emacs ()
  759. {
  760. #ifndef CANNOT_DUMP
  761. #ifdef HAVE_SHM
  762.   defsubr (&Sdump_emacs_data);
  763. #else
  764.   defsubr (&Sdump_emacs);
  765. #endif
  766. #endif /* not CANNOT_DUMP */
  767.  
  768.   defsubr (&Skill_emacs);
  769.  
  770.   DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
  771.     "Args passed by shell to Emacs, as a list of strings.");
  772.  
  773.   DEFVAR_LISP ("system-type", &Vsystem_type,
  774.     "Symbol indicating type of operating system you are using.");
  775.   Vsystem_type = intern (SYSTEM_TYPE);
  776.  
  777.   DEFVAR_BOOL ("noninteractive", &noninteractive1,
  778.     "Non-nil means Emacs is running without interactive terminal.");
  779.  
  780.   Vkill_emacs_hook = Qnil;
  781.  
  782.   DEFVAR_LISP ("kill-emacs-hook", &Vkill_emacs_hook,
  783.     "Function called, if non-nil, whenever kill-emacs is called.");
  784. }
  785.